import Vue from 'vue'
import VueRouter from 'vue-router'
import Index from "../views/Index";
let Detail = () => import("../views/Detail");
let List = () => import("../views/List");
let Search_list = () => import("../views/Search_list");
let Login = () => import("../views/Login");
let Register = () => import("../views/Register");
Vue.use(VueRouter)

const routes = [
    {
        path: "/",
        component: Index,
        name:"首页"
    },
    {
        path: "/detail/:goodId",
        component: Detail,
        meta:{
            type_flag:true
        },
        name:"商品详情"
    },
    {
        path: "/list/:type",
        component: List,
        name:"商品列表"
    },
    {
        path:"/search_list",
        component:Search_list,
        name:"搜索列表"
    },
    {
        path:"/login",
        component:Login,
        meta:{
            type_flag:true
        },
        name:"登录页"
    },
    {
        path:"/register",
        component:Register,
        meta:{
            type_flag:true
        },
        name:"注册页"
    }
]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes,
    scrollBehavior(to, from, savedPosition) {
        if (savedPosition) {
            return savedPosition
        } else {
            return { x: 0, y: 0 }
        }
    }
})

export default router
